#include "my_structs.h"
#include "adaptive_precision.h"

std::ostream& operator<<(std::ostream& out, cell_t& c)
{
	int x = c.x;
	int y = c.y;
	out << x << " " << y;
	return out;
}

std::istream& operator>>(std::istream& in, point_t& p)
{
	in >> p.x >> p.y;
	return in;
}

line_t::line_t(point_t& p1,point_t& p2):left(p1),right(p2)
{
	if (right.x < left.x)
		std::swap(left,right);
}

bool line_t::if_up_line()
{
	return left.y < right.y;
}

int turn(point_t a, point_t b, point_t c)
{
	double imprecision = 4 * std::numeric_limits<double>::epsilon() * 
		(std::abs((b.x - a.x) * (c.y - a.y)) + std::abs((b.y - a.y) * (c.x - a.x)));
	double product = (b.x - a.x) * (c.y -a.y) - (b.y - a.y) * (c.x - a.x);

	if (product > imprecision) return 1;
	if (product < -imprecision) return -1;
	return adaptive_precision_turn(a.x,a.y,b.x,b.y,c.x,c.y);
}